package com.google.code.bigyang.log;

import com.google.code.bigyang.config.ExtendConfiguration;
import com.google.code.bigyang.util.CommonUtil;

public class Log {

	private static Logger logger;
	
	private static final boolean DEBUG_ENABLE = ExtendConfiguration.isDebugEnable();
	
	static {
		String clazzName = ExtendConfiguration.getLogClassName();
		if(clazzName!=null && !"".equals(clazzName)) {
			try {
				logger = (Logger) Class.forName(clazzName).newInstance();
			} catch (ClassNotFoundException e) {
				LogLog.error("", e);
			} catch (InstantiationException e) {
				LogLog.error("", e);
			} catch (IllegalAccessException e) {
				LogLog.error("", e);
			}
		} else {
			logger = CommonUtil.newInstance(ExtendConfiguration.getLogClassName());
		}
	}
	
	public static void debug(Object message) {
		if(DEBUG_ENABLE) {
			logger.debug(message);
		}
	}
	
	public static void debug(Object message,Throwable thr) {
		if(DEBUG_ENABLE) {
			logger.debug(message, thr);
		}
	}
	
	public static void info(Object message) {
		logger.info(message);
	}
	
	public static void info(Object message,Throwable thr) {
		logger.info(message, thr);
	}
	
	public static void warn(Object message) {
		logger.warn(message);
	}
	
	public static void warn(Object message,Throwable thr) {
		logger.warn(message, thr);
	}
	
	public static void error(Object message) {
		logger.error(message);
	}
	
	public static void error(Object message,Throwable thr) {
		logger.error(message, thr);
	}

}
